package com.ajx.blog.service.impl;

import com.ajx.blog.entity.ArticleComment;
import com.ajx.blog.mapper.ArticleCommentMapper;
import com.ajx.blog.service.api.ArticleCommentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ArticleCommentServiceImpl extends ServiceImpl<ArticleCommentMapper, ArticleComment> implements ArticleCommentService {
    @Autowired
    private ArticleCommentMapper articleCommentMapper;

    @Override
    public int addBackComment(Integer cid, Integer uid, String content) {
        return articleCommentMapper.addBackComment(cid, uid, content);
    }

    @Override
    public Map<Integer, List<ArticleComment>> selectBackComment() {
        Map<Integer, List<ArticleComment>> map = new HashMap<>();
        List<ArticleComment> lsit = articleCommentMapper.selectBackComment();
        for (ArticleComment a : lsit) {
            if(map.get(a.getPid())==null){
                map.put(a.getPid(),new ArrayList<ArticleComment>());
            }
            map.get(a.getPid()).add(a);
        }
        return map;
    }
}
